// 
// Decompiled by Procyon v0.5.36
// 

package com.msw.java;

import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.DriverManager;
import java.sql.Connection;

public class SqlUtils
{
    private static String url;
    
    static {
        SqlUtils.url = "jdbc:mysql://localhost:3306";
        try {
            Class.forName("com.mysql.jdbc.Driver");
        }
        catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    
    public static Connection getConnnection(final String user, final String password) {
        try {
            return DriverManager.getConnection(SqlUtils.url, user, password);
        }
        catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static Connection getConnnection(final String host, final String user, final String password) {
        try {
            String cUrl = null;
            if(host==null || host.trim().length()==0){
            	cUrl = SqlUtils.url;
            }else{
            	cUrl = "jdbc:mysql://"+host;
            }
            return DriverManager.getConnection("jdbc:mysql://"+host, user, password);
        }
        catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }
    
    public static void closeConnection(final Connection conn) throws SQLException {
        if (conn != null) {
            conn.close();
        }
    }
    
    public static ResultSet getResultSet(final Connection conn, final String sql) {
        try {
            final Statement stat = conn.createStatement();
            return stat.executeQuery(sql);
        }
        catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }
}